<?php
/**
 * Created by PhpStorm.
 * User: simon
 * Date: 17-10-16
 * Time: 下午4:12
 */

//redis功能函数测试脚本

require_once('../class/RedisDriver.class.php');
$redis_config = array('host' => '127.0.0.1', 'port' => 6379, 'auth' => '123456');
$redis = RedisDriver::getInstance($redis_config);

//String
var_dump($redis->setex('test',10, 'redis'));
var_dump($redis->setnx('test', 'redis1111'));
var_dump($redis->get('test'));
var_dump($redis->mset(array('sex' => 1, 'age' => 30)));

//Hash
echo '<hr/>';
var_dump($redis->hSet('hash1','username','simon'));
var_dump($redis->hSet('hash1','age','30'));
var_dump($redis->hGet('hash1','username'));
var_dump($redis->hExists('hash1','username'));
/*$redis->hMset('user1', array('username' => 'simon', 'age' => 30));
$redis->hIncrBy('user1', 'age', 2);
var_dump($redis->hMget('user1', 'username,age'));
var_dump($redis->hKeys('user1'));
var_dump($redis->hVals('user1'));
var_dump($redis->hGetAll('user1'));*/

//队列
/*var_dump($redis->rPush('list1', '111'));*/
echo '<hr/>';
var_dump($redis->lPushx('list1', '2222'));
$list11_len = $redis->lLen('list1111');
echo '<hr/>';
echo $list11_len;
var_dump($redis->lRange('list1111', 0, 9));
/*var_dump($redis->lIndex('list11', 0));
var_dump($redis->lSet('list11', 0,'suoy_0'));*/
echo '<hr/>';
//var_dump($redis->lRem('list11', -1, 'suoy_0'));
var_dump($redis->lRange('list1111', 0, 9));
//var_dump($redis->rPop('list11'));

//有序集合
echo '<hr/>';
var_dump($redis->zAdd('set_sort1', 2, '22222'));
var_dump($redis->zRem('set_sort1', '22222'));
var_dump($redis->zRange('set_sort1', 0, -1));
var_dump($redis->zRevRange('set_sort1', 0, -1));
echo '<hr/>';
var_dump($redis->zRangeByScore('set_sort1', '-inf', '+inf', array('withscores' => true, 'limit' => array(0, 2))));
var_dump($redis->zCount('set_sort1', 7, 11));
var_dump($redis->zScore('set_sort1', 111111));
//var_dump($redis->zRank('set_sort1', 111111111));
//var_dump($redis->zRevRank('set_sort1', 111111111));
//var_dump($redis->zCard('set_sort1'));
var_dump($redis->zRemRangeByScore('set_sort1', '-inf', '+inf'));
var_dump($redis->zRangeByScore('set_sort1', '-inf', '+inf', array('withscores' => true)));

//无序集合
echo '<hr/>';
var_dump($redis->sAdd('s_sort1', array(11111, 22222, 33333)));
var_dump($redis->sAdd('s_sort2', array(22222, 33333)));
var_dump($redis->sMembers('s_sort1'));
var_dump($redis->sCard('s_sort1'));
echo '<hr/>';
var_dump($redis->sDiff('s_sort1', 's_sort2'));
//var_dump($redis->sRem('s_sort1','11111'));
//var_dump($redis->sMembers('s_sort1'));

//管理命令
echo '<hr/>';
//var_dump($redis->info());
/*var_dump($redis->keys('list111'));
var_dump($redis->ttl('list111'));
var_dump($redis->getConnInfo('list111'));
var_dump($redis->delKeys('list111'));*/
$array = array('username'=>'zhangsan',age=>30);
$redis->setArr('arr1',$array);
var_dump($redis->getArr('arr1'));

